/*
 * $Id: AbstractGameMap.java 23 2009-03-31 23:37:36Z aaron.day $
 */
package org.crazydays.gameplan.map;


import java.awt.image.BufferedImage;
import java.util.Set;
import java.util.TreeSet;

import org.crazydays.gameplan.map.location.Location;

/**
 * AbstractGameMap is an abstract implementation of a game map.
 */
public abstract class AbstractGameMap
        implements IGameMap
{
	/** name */
	protected String name;

	/** image */
	protected BufferedImage image;

	/** geometry */
	protected Geometry geometry;

	/** locations */
	protected Set<Location> locations;

	/**
	 * AbstractGameMap constructor.
	 * 
	 * @param name Name
	 */
	protected AbstractGameMap(String name)
	{
		setName(name);
		setGeometry(new Geometry());
	}

	/**
	 * AbstractGameMap constructor.
	 * 
	 * @param name Name
	 * @param geometry Geometry
	 */
	protected AbstractGameMap(String name, Geometry geometry)
	{
		setName(name);
		setGeometry(geometry);

		initializeImage();
		initializeLocations();
	}

	/**
	 * Initialize image.
	 */
	protected void initializeImage()
	{
		image =
		        new BufferedImage(getGeometry().getHeight(),
		                getGeometry().getWidth(),
		                BufferedImage.TYPE_4BYTE_ABGR);

		initializeLocations();
	}

	/**
	 * Initialize locations.
	 */
	protected void initializeLocations()
	{
		setLocations(new TreeSet<Location>());
	}

	/**
	 * AbstractGameMap constructor.
	 * 
	 * @param name Name
	 * @param image Image
	 * @param geometry Geometry
	 */
	protected AbstractGameMap(String name, BufferedImage image,
	        Geometry geometry)
	{
		setName(name);
		setGeometry(geometry);
		setImage(image);
	}

	/**
	 * Set name.
	 * 
	 * @param name Name
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Get name.
	 * 
	 * @return Name
	 * @see org.crazydays.gameplan.map.IGameMap#getName()
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Set image.
	 * 
	 * @param image Image
	 */
	public void setImage(BufferedImage image)
	{
		this.image = image;
	}

	/**
	 * Get image.
	 * 
	 * @return Image
	 * @see org.crazydays.gameplan.map.IGameMap#getImage()
	 */
	public BufferedImage getImage()
	{
		return image;
	}

	/**
	 * Set geometry.
	 * 
	 * @param geometry Geometry
	 */
	public void setGeometry(Geometry geometry)
	{
		this.geometry = geometry;
	}

	/**
	 * Get geometry.
	 * 
	 * @return Geometry
	 * @see org.crazydays.gameplan.map.IGameMap#getGeometry()
	 */
	public Geometry getGeometry()
	{
		return geometry;
	}

	/**
	 * Set locations.
	 * 
	 * @param locations Locations
	 */
	public void setLocations(Set<Location> locations)
	{
		this.locations = locations;
	}

	/**
	 * Get locations.
	 * 
	 * @return Locations
	 * @see org.crazydays.gameplan.map.IGameMap#getLocations()
	 */
	public Set<Location> getLocations()
	{
		return locations;
	}

	/**
	 * Compare to game map.
	 * 
	 * @param gameMap Game map
	 * @return Comparison
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(IGameMap gameMap)
	{
		return getName().compareTo(gameMap.getName());
	}

	/**
	 * Get hash code.
	 * 
	 * @return Hash code
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode()
	{
		return getName().hashCode();
	}

	/**
	 * Equal game map.
	 * 
	 * @param object IGameMap
	 * @return Equals
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object object)
	{
		if (object instanceof IGameMap) {
			return getName().equals(((IGameMap) object).getName());
		} else {
			return false;
		}
	}
}
